﻿@*
    Project: Aguafrommars/TheIdServer
    Copyright (c) 2022 @Olivier Lefebvre
*@
@inject IViewLocalizer Localizer

@model LoginViewModel


<div class="login-page">
    <div class="page-header">
        <h1>@Localizer["Login"]</h1>
    </div>

    <partial name="_ValidationSummary" />

    <div class="row">

        @if (Model.EnableLocalLogin)
        {
            <div class="col-sm-6 mb-2">
                <div class="card">
                    <div class="card-header">
                        <h3 class="panel-title">@Localizer["Local Login"]</h3>
                    </div>
                    <div class="card-body">
                        <form asp-route="Login">
                            <input type="hidden" asp-for="ReturnUrl" />
                            <fieldset>
                                <legend class="visually-hidden">@Localizer["Login form"]</legend>
                                <div class="row">
                                    <div class="col-md">
                                        <div class="form-floating mb-2">
                                            <input class="form-control" placeholder="@Localizer["Username"]" asp-for="Username" autofocus>
                                            <label class="form-label" asp-for="Username">@Localizer["Username"]</label>
                                        </div>
                                        <div class="form-floating mb-2">
                                            <input type="password" class="form-control" placeholder="@Localizer["Password"]" asp-for="Password" autocomplete="off">
                                            <label class="form-label" asp-for="Password">@Localizer["Password"]</label>
                                        </div>
                                        <button class="w-100 btn btn-lg btn-primary mb-2" name="button" value="login">
                                            @Localizer["Login"]
                                        </button>
                                        <button class="w-100 btn btn-lg btn btn-secondary mb-3" name="button" value="cancel">@Localizer["Cancel"]</button>
                                        @if (Model.AllowRememberLogin)
                                        {
                                            <div class="login-remember mb-3">
                                                <label asp-for="RememberLogin">
                                                    <input asp-for="RememberLogin">
                                                    <strong>@Localizer["Remember My Login"]</strong>
                                                </label>
                                            </div>
                                        }
                                        <div>
                                            @if (Model.ShowForgotPassworLink)
                                            {
                                                <p>
                                                    <a asp-area="Identity" asp-page="/Account/ForgotPassword" asp-route-returnUrl="@Model.ReturnUrl">@Localizer["Forgot your password?"]</a>
                                                </p>
                                            }
                                            @if (Model.ShowRegisterLink)
                                            {
                                                <p>
                                                    <a asp-area="Identity" asp-page="/Account/Register" asp-route-returnUrl="@Model.ReturnUrl">@Localizer["Register as a new user"]</a>
                                                </p>
                                            }
                                            @if (Model.ShowResendEmailConfirmationLink)
                                            {
                                                <p>
                                                    <a asp-area="Identity" asp-page="/Account/ResendEmailConfirmation">@Localizer["Resend email confirmation"]</a>
                                                </p>
                                            }
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        }

        @if (Model.VisibleExternalProviders.Any())
        {
            <div class="col-sm-6 external-providers">
                <div class="card">
                    <div class="card-header">
                        <h3 class="panel-title">@Localizer["External Login"]</h3>
                    </div>
                    <div class="card-body">
                        <ul class="list-inline">
                            @foreach (var provider in Model.VisibleExternalProviders)
                            {
                                <li class="list-inline-item">
                                    <a class="btn btn-lg btn-secondary mb-2"
                               asp-controller="External"
                               asp-action="Challenge"
                               asp-route-provider="@provider.AuthenticationScheme"
                               asp-route-returnUrl="@Model.ReturnUrl">
                                        @provider.DisplayName
                                    </a>
                                </li>
                            }
                        </ul>
                    </div>
                </div>
            </div>
        }

        @if (!Model.EnableLocalLogin && !Model.VisibleExternalProviders.Any())
        {
            <div class="alert alert-warning">
                <strong>
                    @Localizer["Invalid login request"]
                </strong>

                @Localizer["There are no login schemes configured for this client."]
            </div>
        }
    </div>
</div>